#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
typedef int datatype;
typedef struct Lnode
{
    datatype data;
    struct Lnode* next;
}Lnode;

void pushback(Lnode** L, int arr[],int sz)
{
        Lnode* end;
        end = (*L);
        for (int i = 0; i < sz; i++)
        {
            Lnode* node = (Lnode*)malloc(sizeof(Lnode));
            node->data = arr[i];
            end->next = node;
            end = node;
        }
        end->next = NULL;

    }

int pop(Lnode** L, int n)
{
    Lnode* prev = (*L);
    int count = 0;
    int ret = 0;
    while (count != n-1)
    {
        prev = prev->next;
        count++;
    }

    Lnode* p = prev->next;
    ret=p->data;
    prev->next = p->next;
    free(p);
    return ret;
}
    int main()
    {
        Lnode* L = (Lnode*)malloc(sizeof(Lnode));
        L->next = NULL;
        int arr[5] = { 1,2,3,4,5 };
        int sz = sizeof(arr) / sizeof(arr[0]);
        pushback(&L, arr, sz);
        int n = 0;
        scanf("%d", &n);
        int ret=pop(&L, n);
        printf("%d\n", ret);
        Lnode* p = L->next;
        while (p != NULL)
        {
            printf("%d ", p->data);
            p = p->next;
        }
    }